var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var path = require('path');
sqlFile = path.resolve(__dirname,'./db/data.db');
function db(){
    return new sqlite3.Database(sqlFile,function(err){
        if(err) console.log(err);
    });
}
/*var db = new sqlite3.Database(sqlFile,function(err){
    if(err) console.log(err);
});*/
 
/*db.serialize(function() {
  db.run("CREATE TABLE IF NOT EXISTS test (info TEXT,datetime TIMESTAMP)");
  var stmt = db.prepare("INSERT INTO test VALUES (?,?)");
  for (var i = 0; i < 10; i++) {
      stmt.run("Ipsum " + i,Date.now());
  }
  stmt.finalize();
  db.each("SELECT rowid AS id, info,datetime FROM test", function(err, row) {
      console.log(row.id + ": " + row.info + "-" + row.datetime);
  });
});*/
 
//db.close();
module.exports = db;

/**
 * 表结构 
 * 
  CREATE TABLE "test" (
      "id" INTEGER PRIMARY KEY  NOT NULL ,
      "info" TEXT,
      "datetime"  DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime'))
      )
CREATE TABLE t_city (
    cityName varchar (50) NOT NULL,
    provinceId INT,
    cityId INTEGER PRIMARY KEY
    )
CREATE TABLE t_province (
    provinceName varchar (50) NOT NULL,
    provinceId INTEGER PRIMARY KEY,
    proRemark varchar (50)
    )
CREATE TABLE t_zone (
    zoneId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    zoneName TEXT,
    cityId INT
    )
 */